import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController } from 'ionic-angular';

/**
 * Generated class for the DemoToastPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-demo-toast',
  templateUrl: 'demo-toast.html',
})
export class DemoToastPage {
  constructor(public navCtrl: NavController, public navParams: NavParams, public toastCtrl: ToastController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad DemoToastPage');
  }

  showToast(msg, postion, duration) {
    let optstr = postion ? postion : 'bottom'
    let dur = duration ? duration : 2000
    let newToast = this.toastCtrl.create({
      message : msg,
      duration : dur,
      position : optstr
    });
    newToast.present();
  }

  showToast_cust(msg) {
    let newToast = this.toastCtrl.create({
      message : msg,
      showCloseButton : true,
      closeButtonText : '关闭',
      //class只能影响外部的遮罩，而且只能将css写在appscss中，因为toast不在单页范围内
      cssClass : 'custToast'
    });
    //指定关闭toast后的触发事件
    newToast.onDidDismiss(this.dismissHandler)
    newToast.present();
  }

  dismissHandler() {
    alert('Toast Dismiss ！')
  }
}
